package cn.school;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Scanner;

import cn.school.util.DBUtil;

public class GetStuPage {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		System.out.println("请输入页码和条数:");
		int pageNo = in.nextInt();
		int pageSize = in.nextInt();
		int offset = (pageNo - 1) * pageSize;
		offset = Math.max(offset, 0);// 不能小于0
		String sql = "select * from s_student order by stuno asc limit ?,?";
		try (Connection con = DBUtil.getConnection(); PreparedStatement ps = con.prepareStatement(sql);) {

			ps.setInt(1, offset);
			ps.setInt(2, pageSize);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				System.out.println(rs.getLong("stuno") + "," + rs.getString("sname"));

			}

			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
